package com.ruoyi.web.controller.info;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.info.domain.SysGrade;
import com.ruoyi.info.service.ISysGradeService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 年级信息Controller
 *
 * @author silencezheng
 * @date 2022-10-19
 */
@RestController
@RequestMapping("/info/grade")
public class SysGradeController extends BaseController {
	@Autowired
	private ISysGradeService sysGradeService;

	/**
	 * 查询年级信息列表
	 */
	@PreAuthorize("@ss.hasPermi('info:grade:list')")
	@GetMapping("/list")
	public TableDataInfo list(SysGrade sysGrade) {
		startPage();
		List<SysGrade> list = sysGradeService.selectSysGradeList(sysGrade);
		return getDataTable(list);
	}

	/**
	 * 导出年级信息列表
	 */
	@PreAuthorize("@ss.hasPermi('info:grade:export')")
	@Log(title = "年级信息", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	public void export(HttpServletResponse response, SysGrade sysGrade) {
		List<SysGrade> list = sysGradeService.selectSysGradeList(sysGrade);
		ExcelUtil<SysGrade> util = new ExcelUtil<SysGrade>(SysGrade.class);
		util.exportExcel(response, list, "年级信息数据");
	}

	/**
	 * 获取年级信息详细信息
	 */
	@PreAuthorize("@ss.hasPermi('info:grade:query')")
	@GetMapping(value = "/{id}")
	public AjaxResult getInfo(@PathVariable("id") Long id) {
		return AjaxResult.success(sysGradeService.selectSysGradeById(id));
	}

	/**
	 * 新增年级信息
	 */
	@PreAuthorize("@ss.hasPermi('info:grade:add')")
	@Log(title = "年级信息", businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@RequestBody SysGrade sysGrade) {
		sysGrade.setCreateBy(getUsername());
		return toAjax(sysGradeService.insertSysGrade(sysGrade));
	}

	/**
	 * 修改年级信息
	 */
	@PreAuthorize("@ss.hasPermi('info:grade:edit')")
	@Log(title = "年级信息", businessType = BusinessType.UPDATE)
	@PutMapping
	public AjaxResult edit(@RequestBody SysGrade sysGrade) {
		sysGrade.setUpdateBy(getUsername());
		return toAjax(sysGradeService.updateSysGrade(sysGrade));
	}

	/**
	 * 删除年级信息
	 */
	@PreAuthorize("@ss.hasPermi('info:grade:remove')")
	@Log(title = "年级信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
	public AjaxResult remove(@PathVariable Long[] ids) {
		return toAjax(sysGradeService.deleteSysGradeByIds(ids));
	}
}
